package 其他;

public class 最长连续子序列 {
    public int longestCommonSubsequence(String text1, String text2) {
        int[][] res = new int[text1.length() + 1][text2.length() + 1];
        int max = 0;
        for(int i = 1; i < text1.length() + 1; i++){
            char c = text1.charAt(i);
            for(int j = 1; j < text2.length() + 1; j++){
                char s = text2.charAt(j);
                if(c == s){
                    res[i][j] = res[i - 1][j - 1] + 1;
                }else{
                    res[i][j] = Math.max(res[i - 1][j],res[i][j - 1]);
                }
                max = Math.max(max,res[i][j]);
            }
        }
        return max;
    }
}
